
package model.img;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;


public class HistGray implements Filtro{

    @Override
    public String getName() {
        return "Histograma Gray";
    }

    @Override
    public Map<String, List> filtrar(String image) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Mat imgGray = Highgui.imread("./src/data/img/"+image, 0);
        int colunas = imgGray.cols() / 2;
        int linhas = imgGray.rows() / 2;
        double[] valorRGB;
        int a = 0;
        int valorArray;

        List<Integer> histGray = new ArrayList<>();
        for (int i = 0; i < 255; i++) {
            histGray.add(i, 0);
        }
        for (int i = 0; i < linhas; i++) {
            for (int j = 0; j < colunas; j++) {
                valorRGB = imgGray.get(i, j);
                a = (int) valorRGB[0];
                valorArray = histGray.get(a);
                valorArray += 1;
                histGray.set(a, valorArray);
            }
        }
        Map<String, List> valores = new HashMap();
        valores.put("Gray", histGray);
        return  valores;
    }
    
}
